#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

int GetMonthDay(int year, int month)
{
    int monthArray[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31 };

    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
        return 29;

    return monthArray[month];
}

int main()
{
    int input, year, month, day, count, daytotal;
    cin >> input;
    for (int i = 0; i < input; i++)
    {
        cin >> year >> month >> day >> daytotal;
        day += daytotal;
        while (day / GetMonthDay(year, month) != 0)
        {
            if (day / GetMonthDay(year, month) == 1 && day == GetMonthDay(year, month))
            {
                break;
            }
            day -= GetMonthDay(year, month);
            month++;
            if (month == 13)
            {
                month = 1;
                year++;
            }
        }
        printf("%d-%02d-%02d\n", year, month, day);
    }
}